package com.zw.a.basic.a02.demo04_if;

import java.util.Scanner;

//案例: 演示判断奇偶数.
public class IfDemo03 {
    public static void main(String[] args) {
        //1.提示用户键盘录入一个数据并接收.
        System.out.println("请录入一个数字: ");
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();

        //2.判断该数据是奇数还是偶数, 并将结果打印到控制台上.
        //方式1: if.else实现
        if (num % 2 == 0) {
            System.out.println(num + "是偶数");
        } else {
            System.out.println(num + "是奇数");
        }
        System.out.println("------------------------");

        //方式2: 三元运算符
        System.out.println(num + (num % 2 == 0 ? "是偶数" : "是奇数"));
    }
}
